<%
  # Required Arguments:
  # => pageargs['race']
  #       The race object which going to display.
  # => pageargs['batches']
  #       The race_batch object which related to the race
  # => pageargs['batch']
  #       The latest batch object which related to the race
  # => pageargs['win_place']
  #       The latest win place data related to the race
  # => pageargs['quinella']
  #       The latest quinella data related to the race
  # => pageargs['quinella_place']
  #       The latest q place data related to the race
%>

% if pageargs['race']:
<div class="race-info">
  <h1>[Race ${pageargs['race'].race_no}] ${pageargs['race'].display_race_time()}</h1>
  <div class="basic-info">
    <div class="row clear-wrapper">
      <div class="field">Race no:</div>
      <div class="value">${pageargs['race'].race_no}</div>
    </div>
    <div class="row clear-wrapper">
      <div class="field">Venue:</div>
      <div class="value">${pageargs['race'].venue}</div>
    </div>
    <div class="row clear-wrapper">
      <div class="field">Race time:</div>
      <div class="value">${pageargs['race'].display_race_time()}</div>
    </div>
    % if pageargs['race'].time_remaining():
    <div class="row clear-wrapper">
      <div class="field">Time Remaining:</div>
      <div class="value">${pageargs['race'].time_remaining()}</div>
    </div>
    % endif
    % if pageargs['race'].result:
    <div class="row clear-wrapper">
      <div class="field">Result:</div>
      <div class="value">${pageargs['race'].result}</div>
    </div>
    % endif
    <div class="row clear-wrapper">
      <div class="field">Num of batches:</div>
      <div class="value">
        ${pageargs['batches'].count()}
        <select onChange="window.location=this[selectedIndex].value;">
          % for batch in pageargs['batches']:
          <%
            selected = ''
            if pageargs['batch'].batch_time == batch.batch_time:
              selected = 'SELECTED'
          %>
          <option value="/races/show/${pageargs['race'].key()}/batch/${batch.key()}" ${selected}>${batch.time_diff_to_race_time()}</option>
          % endfor
        </select>
      </div>
    </div>
  </div>
</div>

% if pageargs['batch']:
<div class="pool-info">
  <h2>Betting Pool</h2>
  <table>
    <tr><th>Win</th><th>Place</th><th>Quinella</th><th>Q Place</th><th>Double</th><th>Tierce</th><th>Trio</th><th>First 4</th></tr>
    <tr>
      <td>${pageargs['batch'].win_pool}</td>
      <td>${pageargs['batch'].place_pool}</td>
      <td>${pageargs['batch'].quinella_pool}</td>
      <td>${pageargs['batch'].quinella_place_pool}</td>
      <td>${pageargs['batch'].double_pool}</td>
      <td>${pageargs['batch'].tierce_pool}</td>
      <td>${pageargs['batch'].trio_pool}</td>
      <td>${pageargs['batch'].first_four_pool}</td>
    </tr>
  </table>
</div>
% endif

<div class="odds-container clear-wrapper">
  <div class="left">
    <div class="twin-odds widget">
      <h2>Quinella</h2>
      <%include file="/races/twin_odds_display.html" args="twin_odds=pageargs['quinella']"/>
    </div>
    <div class="twin-odds widget">
      <h2>Quinella Place</h2>
      <%include file="/races/twin_odds_display.html" args="twin_odds=pageargs['quinella_place']"/>
    </div>
  </div>
  <div class="right">
    % if pageargs['win_place']:
    <div class="win-place widget">
      <h2>Win Place Odds</h2>
      <table>
        <tr><th>Horse No</th><th>Win</th><th>Place</th></tr>
        % for win_place in pageargs['win_place']:
        <tr>
          <td>${win_place.horse_no}</td>
          <td>${win_place.win}</td>
          <td>${win_place.place}</td>
        </tr>
        % endfor
      </table>
    </div>
    % endif
  </div>
</div>

% endif